package com.zclcs.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zclcs.model.DataRet;
import com.zclcs.model.Role;
import com.zclcs.model.RoleUser;
import com.zclcs.service.RoleService;

/**
 * 角色控制器 GET 用来获取资源， POST 用来新建资源（也可以用于更新资源）， PUT 用来更新资源， DELETE 用来删除资源。
 * 
 * @author 周成龙
 *
 */
@RestController
public class RoleController {

	@Autowired
	private RoleService roleService;

	@GetMapping(value = "/role/selectRolePage")
	public DataRet<IPage<Role>> selectRolePage(Role role) {

		return new DataRet<IPage<Role>>(roleService.selectRolePage(role));

	}

	@PostMapping(value = "/role/insertRole")
	public void insertRole(Role role) {

		roleService.insertRole(role);

	}

	@PutMapping(value = "/role/updateRole")
	public void updateRole(Role role) {

		roleService.updateRole(role);

	}

	@DeleteMapping(value = "/role/deleteRole")
	public DataRet<Object> deleteRole(@RequestParam(value = "ids[]") List<String> ids) {

		return roleService.deleteRole(ids);

	}

	@PostMapping(value = "/role/validRolename")
	public DataRet<Object> validRolename(Role role) {

		return new DataRet<Object>(roleService.validRoleName(role));

	}

	@PostMapping(value = "/role/pickUpRoles")
	public void pickUpRoles(RoleUser roleUser) {

		roleService.pickUpRoles(roleUser);

	}

	@DeleteMapping(value = "/role/putDownRoles")
	public void putDownRoles(RoleUser roleUser) {

		roleService.putDownRoles(roleUser);

	}

}
